package com.fayou.cloud.cloudconsumeropenfeignorder8082.controller;

import com.fayou.cloud.cloudconsumeropenfeignorder8082.service.FeignPaymentService;
import com.fayou.cloud.entites.CommonResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/consumer/openFeign/payment")
public class OrderController {

    @Resource
    FeignPaymentService feignPaymentService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/selectOne")
    public CommonResult selectOne(@RequestParam Integer id) {
        CommonResult payment = feignPaymentService.selectOne(id);
        return payment;
    }

    @GetMapping("/timeout")
    public String paymentFeignTimeout() {
        return feignPaymentService.paymentFeignTimeout();
    }


    @GetMapping("/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id) {
        return feignPaymentService.paymentInfo_OK(id);
    }

    @GetMapping("/hystrix/timeout/{id}")
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id){
        return feignPaymentService.paymentInfo_TimeOut(id);
    }

    //====服务熔断
    @GetMapping("/circuit/{id}")
    public String paymentCircuitBreaker(@PathVariable("id") Integer id){
        return feignPaymentService.paymentCircuitBreaker(id);
    }
}
